<!DOCTYPE html>
<html>
<head>
    <title>找回密码-{eju:global name='web_title' /}</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/plugins/layui/css/layui.css?v={$version}" media="all">
    <link rel="stylesheet" href="__SKIN__/css/admin.css?v={$version}" media="all">
    <link rel="stylesheet" href="__SKIN__/css/login.css?v={$version}" media="all">
    <link rel="stylesheet" href="__SKIN__/css/ey_layui.css?v={$version}" media="all">
    <link rel="stylesheet" href="__SKIN__/css/page.css?v={$version}" media="all">
    <link rel="stylesheet" href="__SKIN__/css/perfect-scrollbar.css?v={$version}" media="all">
    <script type="text/javascript">
        var eyou_basefile = window.location.pathname;
        var module_name = "{$Think.const.MODULE_NAME}";
        var __root_dir__ = "__ROOT_DIR__";
    </script>

    <script type="text/javascript" src="__SKIN__/js/jquery.js?v={$version}"></script>
    <script type="text/javascript" src="__SKIN__/js/jquery-ui/jquery-ui.min.js?v={$version}"></script>
    <script type="text/javascript" src="__PUBLIC__/plugins/layer-v3.1.0/layer.js?v={$version}"></script>
    <script type="text/javascript" src="__SKIN__/js/jquery.cookie.js?v={$version}"></script>
    <script type="text/javascript" src="__PUBLIC__/plugins/laydate/laydate.js?v={$version}"></script>
    <script type="text/javascript" src="__PUBLIC__/plugins/layui/layui.js?v={$version}"></script>
    <script type="text/javascript" src="__SKIN__/js/global.js?v={$version}"></script>
    <script type="text/javascript" src="__SKIN__/js/add_js/perfect-scrollbar.js?v={$version}"></script>

</head>
<body>
 <div class="login-bg">
	  <div class="w1200">
		<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
			<div class="layadmin-user-login-main">
				<div class="layadmin-user-login-box layadmin-user-login-header">
					<div style="margin-bottom: 10px;"><img height="34" src="{eju:global name='web_logo' /}" alt=""></div>
					<p>找回密码</p>
				</div>
				<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="email"></label>
						<input type="text" name="email" id="email" lay-verify="email" placeholder="邮箱" class="layui-input">
					</div>
					{eju:eq name="$is_vertify" value="1"}
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="vertify"></label>
								<input type="text" name="vertify" id="vertify" lay-verify="required" placeholder="图形验证码" class="layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<img src="{eju:url link='api/Ajax/vertify' vars='type=users_retrieve_password' /}"  id="LAY-user-get-vercode"  class="layadmin-user-login-codeimg" >
								</div>
							</div>
						</div>
					</div>
					{/eju:eq}
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="email_code"></label>
								<input type="text" name="email_code" id="email_code" lay-verify="required" placeholder="邮箱验证码" class="layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<button type="button" onclick="get_email_code();"  class="layui-btn layui-btn-primary layui-btn-fluid" id="email_button">点击发送</button>
								</div>
							</div>
						</div>
					</div>


					<div class="layui-form-item">
						<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="formSubmit">下一步</button>
					</div>
					<div class="layui-trans layui-form-item layadmin-user-login-other">
						<a href="{eju:url link='user/Users/login' /}" class="layadmin-user-jump-change layadmin-link layui-hide-xs">返回登陆</a>
					</div>
				</div>
			</div>
		</div>
	  </div>
</div>
<script>
    function get_email_code()
    {
        var email = $("#email").val();
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        // 邮箱格式不正确
        if(!reg.test(email)){
            layer.msg('请正确输入邮箱地址！', {time: 2000});
            return false;
        }
        var vertify = "";
        if ($("#vertify")){
            vertify = $("#vertify").val();
            if (vertify == ''){
                layer.msg('请输入验证码', {time: 2000});
                return false;
            }
        }
        $("#email_button").val('发送中…');
        $("#email_button").attr('disabled', 'disabled');
        var title = '找回密码';
        $.ajax({
            url: "{eju:url link='user/Smtpmail/send_email_retrieve' /}",
            data: {email:email,title:title,type:'retrieve_password',scene:4,vertify:vertify},
            type:'post',
            dataType:'json',
            success:function(res){
                if(res.code == 1){
                    layer.msg(res.msg, {time: 2000});
                    countdown();
                }else{
                    $("#email_button").val('点击发送');
                    $("#email_button").removeAttr("disabled");
                    $('#LAY-user-get-vercode').trigger('click');
                    layer.alert(res.msg, {icon: 2});
                }
            },
            error : function() {
                $("#email_button").val('点击发送');
                $("#email_button").removeAttr("disabled");
                $('#LAY-user-get-vercode').trigger('click');
                layer.alert('网络失败，请刷新页面后重试', {icon: 5});
            }
        });
    }
    layui.config({
        base: '__SKIN__/' //静态资源所在路径
        ,version: '{$version}'
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function(){
        var $ = layui.$
            ,setter = layui.setter
            ,admin = layui.admin
            ,form = layui.form
            ,router = layui.router();

        form.render();

        form.verify({

        });
        $(document).on('click','#LAY-user-get-vercode', function(){
            var src = "{eju:url link='api/Ajax/vertify' vars='type=users_retrieve_password' /}";
            if (src.indexOf('?') > -1) {
                src += '&';
            } else {
                src += '?';
            }
            src += 'r='+Math.floor(Math.random()*100);
            console.log(src);
            $(this).attr('src', src);//重载验证码
        });

        $(document).keydown(function(event){
            if(event.keyCode ==13){
                $('div button[lay-filter=formSubmit]').trigger('click');
            }
        });
        //提交
        form.on('submit(formSubmit)', function(data){
            var load = layer_loading();
            //确认密码
            if(data.field.password !== data.field.verify_password){
                return layer.msg('两次密码输入不一致');
            }
            //请求接口
            data.field._ajax = 1;
            $.ajax({
                type : 'post',
                url : "{:url('Users/retrieve_password')}",
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.close(load); //关闭loading
                    if (1 == res.code) {
                        window.location.href = res.url;
                    } else {
                        $('#LAY-user-get-vercode').trigger('click');
                        layer.msg(res.msg, {icon: 5, title:false});
                        return false;
                    }
                },
                error: function(e){
                    layer.close(load); //关闭loading
                    showErrorAlert();
                }
            });

            return false;
        });
    });
    function countdown(){
        // 倒计时
        var setTime;
        var time = {php}echo config('global.email_send_time');{/php};
        setTime = setInterval(function(){
            if(0 >= time){
                clearInterval(setTime);
                return;
            }
            time--;
            $("#email_button").html(time+'秒');
            $("#email_button").attr('disabled', 'disabled');
            if(time == 0){
                $("#email_button").html('点击发送');
                $("#email_button").removeAttr("disabled");
            }
        },1000);
    }
</script>
	<script type="text/javascript" src="{eju:global name='web_templets_pc' /}/skin/js/common.js"></script>
</body>
</html>